<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="..${ctx}/common/define"/>

<div class="pageContent">
	<form method="post" action="${path}/submitSearchActionUnit.html" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
		<input type="hidden" id="open_state" name="state" value="${state}" />
		<input type="hidden" id="action_name" name="action_name" value="${name}" />
		<div class="pageFormContent" layoutH="200">
			<fieldset>
				<legend>基本信息</legend>
				<dl >
					<dt>操作名称：</dt>
					<dd><input name="name" type="text" size="30" value="${unit.name}" class="required" /></dd>
				</dl>
				<dl >
					<dt>操作说明：</dt>
					<dd><input name="description" type="text" size="30" value="${unit.description}" class="required" /></dd>
				</dl>
				<dl >
					<dt>引用操作键名：</dt>
					<dd><input name="ref" type="text" size="30" value="${unit.ref}" /></dd>
				</dl>
				<dl >
					<dt>查询类型：</dt>
					<dd>
						<select class="combox" name="type">
							<option <c:if test="${bean.type=='single'}">selected</c:if> value="single">单个查询</option>
							<option <c:if test="${bean.type=='map'}">selected</c:if> value="map">Map查询</option>
							<option <c:if test="${bean.type=='list'}">selected</c:if> value="list">列表查询</option>
							<option <c:if test="${bean.type=='paging'}">selected</c:if> value="paging">分页查询</option>
						</select>
					</dd>
				</dl>
				<dl >
					<dt>起用缓存：</dt>
					<dd>
						<select class="combox" name="cache">
							<option value="0" <c:if test="${bean.cache}">selected</c:if> >不用</option>
							<option value="1" <c:if test="${bean.cache}">selected</c:if> >使用</option>
						</select>
					</dd>
				</dl>
				<dl >
					<dt>Map类键名：</dt>
					<dd><input name="mapKey" type="text" size="30" value="${bean.mapKey}" /></dd>
				</dl>
				<dl class="nowrap">
					<dt>SQL文：</dt>
					<dd><textarea name="sql" cols="90" rows="5" class="required">${bean.sql}</textarea></dd>
				</dl>
			</fieldset>
		</div>

		<div class="pageFormContent" layoutH="300">
			<div class="tabs">
			<div class="tabsHeader">
				<div class="tabsHeaderContent">
					<ul>
						<li class="selected"><a href="javascript:void(0)"><span>参数列表</span></a></li>
					</ul>
				</div>
			</div>
			<div class="tabsContent" style="height: 220px;">
				<div>
					<table class="list nowrap itemDetail" addButton="添加参数" width="100%">
						<thead>
							<tr>
								<th type="text" name="items.key[#index#]" size="10" fieldClass="required">键名</th>
								<th type="text" name="items.sql[#index#]" size="45" fieldClass="required">SQL语句</th>
								<th type="lookup" name="items[#index#].org.name" lookupGroup="items[#index#].org" 
								suggestUrl="..${ctx}/common/view.html?jsp=base/com/java_data_type_list" suggestFields="name" size="20" 
								fieldClass="required">数据类型</th>
								<th type="text" name="items.format[#index#]" size="10">格式</th>
								<th type="text" name="items.defaultValue[#index#]" size="10">默认值</th>
								<th type="lookup" name="items[#index#].force.name" lookupGroup="items[#index#].force" 
								suggestUrl="..${ctx}/common/view.html?jsp=base/com/yes_no_list" suggestFields="name" size="2" >强制</th>
								<th type="del" width="30">操作</th>
							</tr>
						</thead>
						<tbody>
							<c:if test="${! empty bean.paramenters }">
							<c:forEach var="data" items="${bean.paramenters}" varStatus="status">
							<tr>
								<td>
									<input type="text" class="required textInput" size="10" value="${data.key}" name="items.key[${status.index}]" />
								</td>
								<td><input type="text" class="required textInput" size="45" value="${data.sql}" name="items.sql[${status.index}]" /></td>
								<td>
									<input type="hidden" name="items[${status.index}].org.id" value="${data.type}" />
									<input type="text" name="items[${status.index}].org.name"  size="20" lookuppk="id" 
									suggesturl="..${ctx}/common/view.html?jsp=base/com/java_data_type_list" class="required textInput" 
									lookupgroup="items[${status.index}].org" autocomplete="off" value="${data.typeString}" postfield="" suggestfields="name" />
								</td>
								<td><input type="text" class="textInput" size="10" value="${data.format}" name="items.format[${status.index}]" /></td>
								<td><input type="text" class="textInput" size="10" value="${data.defaultValue}" name="items.defaultValue[${status.index}]" /></td>
								<td>
									<input type="hidden" name="items[${status.index}].force.id" value="${data.force}" />
									<input type="text" name="items[${status.index}].force.name"  size="2"  lookuppk="id" 
									suggesturl="..${ctx}/common/view.html?jsp=base/com/yes_no_list" class="textInput" 
									lookupgroup="items[${status.index}].force" autocomplete="off" value="${data.forceString}" postfield="" suggestfields="name" />
								</td>
								<td><a class="btnDel " href="javascript:void(0)">删除</a></td>
							</tr>
							</c:forEach>
							</c:if>
						</tbody>
					</table>
				</div>
			</div>
			</div>
		</div>
		
		<div class="formBar">
			<ul>
				<!--<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>-->
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit" >保存</button></div></div></li>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">关闭</button></div></div>
				</li>
			</ul>
		</div>
	</form>
</div>
<script type="text/javascript">
/**
 * dialog上的表单提交回调函数
 * 服务器转回navTabId，可以重新载入指定的navTab. statusCode=DWZ.statusCode.ok表示操作成功, 自动关闭当前dialog
 * form提交后返回json数据结构,json格式和navTabAjaxDone一致
 */
function dialogAjaxDone(json){
	DWZ.ajaxDone(json);
	if (json.statusCode == DWZ.statusCode.ok){
		alertMsg.correct(json.message);
		if(json.callbackType){
			var state = $('#open_state').val();
			if(state == "stand"){
				navTab.reloadFlag("base_define_action_list");// 下次切换到列表页签时需要刷新一下
			}else if(state == "sub"){
				var url = "${path}/getAction.html?name=" + $('#action_name').val();
				navTab.reload(url);
				//navTab.reloadFlag("base_define_add_action");// 下次切换到列表页签时需要刷新一下
			}
			setTimeout(function(){$.pdialog.closeCurrent();}, 100);
		}
	}
}

</script>
